<template>
  <div class="task_container" @keydown.enter="search">
    <div class="task_filter_container">
      <div class="task_filter_search">
        <a-input
          v-model:value="selectedData['search_AND_LIKE_student.name']"
           :placeholder="t('control','请输入学生姓名')"
          style="width: 260px; margin-right: 10px"
        />
      </div>
      <div class="task_filter_btn">
        <a-button
          type="primary"
          @click="search"
          style="margin-right: 10px"
          >{{ t('control','查询') }}</a-button
        >
        <a-button @click="clear">{{ t('control','重置') }}</a-button>
      </div>
    </div>
    <div class="task_list_container">
      <div class="taskList_table_container">
        <a-table
          :dataSource="tableData"
          :columns="columns"
          :pagination="false"
        >
          <template #bodyCell="{ column, text, record, index }">
						<template v-if="column.key == 'studentName'">
						  <span>
						    {{ record.studentName }}
						    <a-tag v-if="record.leader" color="blue" style='margin-left:8px'>{{ t('control','组长') }}</a-tag>
						  </span>
						</template>
						
						<!-- 加入状态列自定义渲染 -->
						<template v-if="column.key === 'auditStatus'">
						  <a-tag :color="record.auditStatus>0 ? 'green' : 'orange'">
						    {{record.auditStatus>0?t('control','已加入'):t('control','待审核') }}
						  </a-tag>
						</template>
          </template>
        </a-table>
      </div>
      <a-pagination
        style="
          text-align: center;
          height: 38px;
          display: flex;
          align-items: center;
          justify-content: center;
        "
        @change="show"
        @showSizeChange="search"
        :current="pagination.current"
        :total="pagination.totalElements"
        :pageSize="pagination.size"
				show-size-changer
      />
    </div>
  </div>
</template>
<script setup>
import { ref, reactive, toRefs, watch, onMounted } from "vue";
import { useRoute, useRouter } from 'vue-router'
import minRangePicker from "@/components/common/minRangePicker.vue";
import {getStudentMemberPage} from '@/request/process/studentMember.js'
import { t } from '@/i18n'

const route = useRoute()
const router = useRouter()

let projectId= ref((route.query&&route.query.id)?route.query.id:'')
onMounted(async ()=>{
	show()
})

async function show(page,pageSize){
	let req = {
    page: page ? page-1 : pagination.value.current - 1,
    size: pageSize || pagination.value.size,
    ...selectedData,
   projectId: projectId.value
	}
	let res = await getStudentMemberPage(req)
	 console.log('成员列表',res)
	if (!res) return
	tableData.value = res.data.content || []
  pagination.value = {
    ...pagination.value,
    current: res.data.page.number + 1,
    totalElements: res.data.page.totalElements,
    size: res.data.page.size
  }
	 // console.log('任务列表',tableData,pagination)
}

function search (page,pageSize){
	show(1,pageSize)
}

//过滤查询
let selectedData = reactive({});


//点击重置按钮
function clear() {
  for (let key in selectedData) {
    selectedData[key] = undefined; // 重置为默认值
  }
  console.log("selectedData", selectedData);
	show()
  // getProjectSquareList();
}

//任务列表
const columns =reactive( [
	{
	  title: t("table","学生姓名"),
	  dataIndex: 'studentName',
	  key: 'studentName',
	},
	{
	  title: t("table",'学号'),
	  dataIndex: 'studentNum',
	  key: 'studentNum',
	},
	{
	  title: t("table",'项目名称'),
	  dataIndex: '111',
	  customRender:()=>route.query.name
	},
	// {
	//   title: '小组Id',
	//   dataIndex: 'teamId',
	//   key: 'teamId',
	// },
	// {
	//   title: '小组名',
	//   dataIndex: 'teamName',
	//   key: 'teamName',
	// },
	// {
	//   title: '年级',
	//   dataIndex: 'year',
	//   key: 'year',
	// },
	// {
	//   title: '班级',
	//   dataIndex: 'className',
	//   key: 'className',
	// },
	{
	  title: t("table",'岗位名称'),
	  dataIndex: 'projectJobName',
	  key: 'projectJobName',
	},
	{
	  title: t("table",'审批状态'),
	  dataIndex: 'auditStatus',
	  key: 'auditStatus',
	}
])
let tableData = ref([]);
let pagination = ref({
  totalElements: 0,
  current: 1,
  size: 10,
});

async function firstShow (){
	if (route.query.template == '1') {
		columns.splice(3,0,	{ title: t('table','组名'), dataIndex: 'teamName', key: 'teamName' })
		columns.splice(4,0,	{ title: t('table','小组编号'), dataIndex: 'teamId', key: 'teamId' })
	}
}
firstShow()

</script>
<style lang="scss" scoped>
@import "@/styles/public.scss";
$filterContainer: 70px;

.task_container {
  width: 100%;
  height: 100%;
  // border: 1px solid blueviolet;
  border-radius: 10px;
  /* padding:20px; */

  .task_filter_container {
    width: 100%;
    height: $filterContainer;
    padding: 20px;
    // border: 1px solid blue;
    display: flex;
    align-items: center;
    justify-content: space-between;
    // border-radius: 10px 10px 0 0;
  }

  .task_list_container {
    width: 100%;
    height: calc(100% - #{$filterContainer});
		padding:15px 20px;
		padding-top:0;
    // border-radius: 0 0 10px 10px;
    // border: 1px solid red;
    display: flex;
    flex-direction: column;
    justify-content: space-between;

    .taskList_table_container {
      width: 100%;
      height: calc(100% - 38px);
      flex: 1;
      min-height: 0;
      overflow: auto;
      @include hoverShowScrollBar();
    }
  }

  .task_detail_container {
    border: 1px solid grey;
    width: 700px;
  }

  // 状态相关样式
  .status {
    &-pending {
      color: #faad14;
    }

    &-completed {
      color: #52c41a;
    }

    &-scored {
      color: #1890ff;
    }
  }
}
</style>
